<template>
  <div class="app-container">
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      stripe
      v-loading="loading"
    >
      <el-table-column prop="productId" label="产品ID" width="100"></el-table-column>
      <el-table-column prop="productName" label="产品名称" width="150"></el-table-column>
      <el-table-column prop="code" label="产品编码" width="120"></el-table-column>
      <el-table-column prop="color" label="颜色" width="100"></el-table-column>
      <el-table-column prop="size" label="尺寸" width="100"></el-table-column>
      <el-table-column prop="status" label="上架状态" width="100">
        <template slot-scope="scope">
          {{ scope.row.status === '1' ? '上架' : '下架' }}
        </template>
      </el-table-column>
      <el-table-column prop="volume" label="体积" width="120"></el-table-column>
      <el-table-column prop="productionTime" label="生产时间" width="150"></el-table-column>
      <el-table-column prop="limitTime" label="到期时间" width="150"></el-table-column>
      <el-table-column prop="basicPrice" label="成本价" width="100"></el-table-column>
      <el-table-column prop="salePrice" label="售价" width="100"></el-table-column>
      <el-table-column prop="numer" label="数量" width="100"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import { getStoragePageList } from '@/api/storage'
export default {
  data() {
    return {
      tableData: [],
      loading: false,
      currentPage: 1,
      pageSize: 10,
      total: 0
    };
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.fetchData();
    },
    fetchData() {
      this.loading = true;
      // 模拟异步请求数据
      getStoragePageList(this.currentPage, this.pageSize)
        .then(response => {
          this.tableData = response.data.records
          this.total = response.data.total
          this.loading = false;
        })
    }
  },
  mounted() {
    this.fetchData();
  }
};
</script>
